package com.dzu.gulimall.order.controller;

import com.dzu.gulimall.order.entity.OrderItemEntity;
import com.dzu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author by ZhaoDong
 * @Classname RabbitController
 * @Description TODO
 * @Date 2021/12/19 21:13
 */
@RestController
public class RabbitController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send/{num}")
    public String sendMsg(@PathVariable("num") Integer num) {

        for (int i = 0; i < num; i++) {
            if (i % 2 == 1) {
                OrderReturnReasonEntity ent = new OrderReturnReasonEntity();
                ent.setId(1L);
                ent.setCreateTime(new Date());
                ent.setName("你好" + i);
                rabbitTemplate.convertAndSend("direct_gulimall_exchange", "gulimall", ent,
                        new CorrelationData(UUID.randomUUID().toString()));
            } else {
                OrderItemEntity ent = new OrderItemEntity();
                ent.setId(1L);
                ent.setSpuName("你号" + i);
                rabbitTemplate.convertAndSend("direct_gulimall_exchange", "gulimall123", ent,
                        new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }
}
